package com.atguigu.tms.mock.service.impl;

import com.atguigu.mock.util.RandomCollection;
import com.atguigu.mock.util.RandomName;
import com.atguigu.tms.mock.bean.BaseComplex;
import com.atguigu.tms.mock.config.AppConfig;
import com.atguigu.tms.mock.mapper.BaseComplexMapper;
import com.atguigu.tms.mock.service.BaseComplexService;
import com.atguigu.tms.mock.service.adv.impl.AdvServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangchen
 * @since 2022-06-12
 */
@Service
public class BaseComplexServiceImpl extends AdvServiceImpl<BaseComplexMapper, BaseComplex> implements BaseComplexService {


    public  void initBaseComplex(Integer complexNum,String cityIds){

        List<BaseComplex> districtList = this.baseMapper.selectAddressList(cityIds);

        List<BaseComplex> baseComplexList = new ArrayList<>();

        for (int i = 0; i < complexNum; i++) {
            BaseComplex baseComplex = RandomCollection.getOneFrom(districtList);
            String complexName = RandomName.getComplexName();
            baseComplex.setComplexName(complexName);
            baseComplex.setCreateTime(new Date());
            baseComplexList.add(baseComplex);
        }
        this.saveOrUpdateBatch(baseComplexList);
        loadCache();

    }

}
